home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / redtop / main.bas < prev    next >
BASIC Source File  |  1994-11-27  |  5KB  |  164 lines

  1. Option Explicit
  2. '
  3. ' ini Constants
  4. '
  5. Global Const SaverName = "Red Top"
  6. Global Const iniName = "CONTROL.INI"
  7. Global iniSection As String
  8. Global Const Version = "Version 1.2"
  9. '
  10. ' Common Globals for all Screen Savers
  11. '
  12. Global PWprotected As Integer
  13. Global Password As Long
  14. Global MouseMove As Integer
  15. Global ValidPassword As Integer
  16. Global OldPassword As Long
  17. '
  18. ' Globals Specific to RedTop
  19. '
  20. Global SpinSpeed As Integer
  21. '
  22. ' API Function Definitions
  23. '
  24. Declare Function ShowCursor Lib "User" (ByVal fShow As Integer) As Integer
  25. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  26. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
  27. Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
  28. Declare Function SetSysModalWindow Lib "User" (ByVal hWnd%) As Integer
  29.  
  30. '
  31. ' Simple Password Routine
  32. '
  33. ' Input:  Password to be calculated
  34. ' Output: Long "Checksum" of Password
  35. '
  36. ' NB. The password maintained in this screen saver is NOT the
  37. '     Standard Windows Screen Saver Password. The password used
  38. '     with this screen saver is maintained in
  39. '     [Screen Saver.Red Top] Section in the Control.ini
  40. '
  41. Function CalcPassnum (Password As String) As Long
  42.  
  43. Dim i As Integer
  44. Dim psum As Long
  45.  
  46.     psum = 0
  47.     For i = 1 To Len(Password)
  48.         psum = psum + ((Asc(Mid$(Password, i, 1)) ^ 2) * i)
  49.     Next i
  50.     
  51.     CalcPassnum = psum
  52.  
  53. End Function
  54.  
  55. '
  56. ' Position the form in centre of the screen
  57. '
  58. Sub CentreForm (F As Form)
  59.  
  60.     F.Move (screen.Width / 2) - (F.Width / 2), (screen.Height / 2) - (F.Height / 2)
  61.  
  62. End Sub
  63.  
  64. '
  65. ' Wrapper for the API call GetPrivateProfileString
  66. '
  67. Function GetIni (IniFile As String, Appname As String, Keyword As String) As String
  68.  
  69. Dim ResultString As String * 128
  70. Dim Temp As Integer
  71.     
  72.     Temp = GetPrivateProfileString(Appname, Keyword, "", ResultString, Len(ResultString), IniFile)
  73.     GetIni = Left$(ResultString, Temp)
  74.  
  75. End Function
  76.  
  77. '
  78. ' Hide the mouse from the screen using API call ShowCursor
  79. '
  80. Sub HideMouse ()
  81.     
  82.     While ShowCursor(False) >= 0
  83.     Wend
  84.  
  85. End Sub
  86.  
  87. '
  88. ' The Initialization of the Screen Saver.
  89. ' Branches to either the saver itself or the configuration form
  90. ' depending on the command line argument "/s or /c"
  91. '
  92. Sub main ()
  93.     '
  94.     ' end if the program is already running
  95.     '
  96.     If App.PrevInstance Then End
  97.     '
  98.     ' Set up the ini Section name
  99.     '
  100.     iniSection = "Screen Saver." & SaverName
  101.     '
  102.     ' Get all the Information from the Initialization file
  103.     '
  104.     PWprotected = Val(GetIni(iniName, iniSection, "PWprotected"))
  105.     Password = CLng(Val(GetIni(iniName, iniSection, "Password")))
  106.     OldPassword = Password
  107.     If (GetIni(iniName, iniSection, "MouseMove")) = "1" Then
  108.         MouseMove = True ' ie will not process MouseMove Event
  109.     Else
  110.         MouseMove = False ' ie will process MouseMove Event
  111.     End If
  112.     '
  113.     ' The value specific to RedTop
  114.     '
  115.     SpinSpeed = Val(GetIni(iniName, iniSection, "SpinSpeed"))
  116.     '
  117.     ' branch to the appropriate form
  118.     '
  119.     If InStr(1, Command$, "/c", 1) Then ' upper or lower case
  120.         frmSetup.Show
  121.     ElseIf InStr(1, Command$, "/s", 1) Then ' upper or lower case
  122.         ' Hide the mouse pointer
  123.         Call HideMouse
  124.         frmSaver.Show
  125.     End If
  126.     
  127. End Sub
  128.  
  129. '
  130. ' Wrapper for the API call WritePrivateProfileString
  131. '
  132. Sub PutIni (IniFile As String, Appname As String, Keyword As String, KeyVal As String)
  133.  
  134. Dim Temp As Integer
  135.     
  136.     Temp = WritePrivateProfileString(Appname, Keyword, KeyVal, IniFile)
  137.  
  138. End Sub
  139.  
  140. '
  141. ' Show the mouse (previously hidden) using API call ShowCursor
  142. '
  143. Sub ShowMouse ()
  144.     
  145.     While ShowCursor(True) < 0
  146.     Wend
  147.  
  148. End Sub
  149.  
  150. '
  151. ' Simple Password Routine
  152. '
  153. ' Input:  Password to be checked, "Checksum" of Password
  154. ' Output: True or False
  155. '
  156. Function ValidatePassword (Password As String, passnum As Long) As Integer
  157.     If CalcPassnum(Password) = passnum Then
  158.         ValidatePassword = True
  159.     Else
  160.         ValidatePassword = False
  161.     End If
  162. End Function
  163.  
  164.